This is an Datasets Notebook. When you execute code within the notebook, the results appear beneath the code.
d <- read.csv("/Users/khaled/Desktop/Programming/Teaching/Datasets/scrubbed.csv", na.strings = "", stringsAsFactors = F) %>% filter(country == "us")
d %>% count(state, sort = T)
d %>% count(shape, sort = T)
d %>% separate(datetime, c("Date", "Time"), sep = " ") -> d
d %>% count(Date, sort = T)
d %>% mutate(Date = mdy(Date)) %>% mutate_at(vars(Date), funs(year, month, day)) -> d
## Warning: funs() is soft deprecated as of dplyr 0.8.0
## please use list() instead
##
## # Before:
## funs(name = f(.))
##
## # After:
## list(name = ~ f(.))
## This warning is displayed once per session.
d %>% mutate(
season = case_when(
month %in% 9:11 ~ "Fall",
month %in% c(12,1,2) ~ "Winter",
month %in% 3:5 ~ "Spring",
TRUE ~ "Summer")) -> d
d %>% count(year, sort = T) %>% ggplot(aes(year, n)) + geom_col()
d %>% group_by(month) %>% mutate(n = n()) %>% select(month, n , season) %>% distinct() %>%
ggplot(aes(month, n)) + geom_col(aes(fill = season)) + scale_x_continuous(breaks = 1:12) +
coord_cartesian(ylim=c(3000,8000)) + geom_smooth(se = F)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
d %>% ggplot(aes(day)) + geom_density() + facet_wrap(~month)
d %>% count(month) %>% ggplot(aes(month, n)) + geom_point() + geom_smooth() +
scale_x_continuous(breaks = 1:12)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
d %>% count(month, sort = T)
d %>% mutate_at(vars(latitude, duration..seconds.), as.numeric) -> d
## Warning: NAs introduced by coercion
# d %>% filter(year == 2012) %>% count(Date) %>% filter(Date == "2012-07-04") -> nn
d %>% filter(year == 2012) %>% group_by(Date) %>% mutate(n = n()) %>%
select(year, Date , n) %>% distinct() -> d2
d2 %>% ggplot(aes(Date, n)) + geom_line() +
ggrepel::geom_label_repel(data = subset(d2,n > 50) , aes(label = as.character(Date)), color = "red", segment.color = "red") +
facet_wrap(~year, scales = "free")
d %>% filter(!state %in% c("ak", "hi", "pr")) %>%
ggplot(aes(longitude, latitude)) +
geom_point(alpha = 0.1) +
coord_map() + borders("state") + theme_void() +
labs(title = 'Year: {round(frame_time)}') +
gganimate::transition_time(year)
##
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
##
## map